package com.tony.reactiveStream;

import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;

import java.util.List;

/**
 * @version V1.0  </br>
 * @ClassName MyReactiveApp </br>
 * @Description TODO  </br>
 * @Author tonywang</br>
 * @DATE 3/14/2019 4:25 PM</br>
 */
public class MyReactiveApp {
    public static void main(String[] args) throws InterruptedException {
        MyPublisher publisher = new MyPublisher();
        MySubscriber subscriber = new MySubscriber();
        publisher.subscribe(subscriber);
        List<Employee> emps = EmpHelper.getEmps();
        // Publish items
        System.out.println("Publishing Items to Subscriber");
        emps.stream().forEach(i -> publisher.submit(i));

        while (emps.size() != subscriber.getCounter()) {
            Thread.sleep(10);
        }

        // close the Publisher
        publisher.close();
        System.out.println("Exiting the app");
    }
}
